package edu.uwo.se2.group3mapapp;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class UserAdapter extends ArrayAdapter<String> {
  private final Context context;
  private final String[] values;

  public UserAdapter(Context context, List<Friend> list) {
	
    super(context, R.layout.friendrowlayout, arrListToStringArray(list));
    this.context = context;
    this.values = arrListToStringArray(list);
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater = (LayoutInflater) context
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView = inflater.inflate(R.layout.friendrowlayout, parent, false);
    TextView textView = (TextView) rowView.findViewById(R.id.label);
    textView.setText(values[position]);

    String s = values[position];


    return rowView;
  }
  
  public static String[] arrListToStringArray(List<Friend> u) {
	  ArrayList<String> un = new ArrayList<String>();
		for(Friend user:u) {
			un.add(user.friendUsername);
		}
		System.out.println(un.toString());
		String[] st = new String[un.size()];
		int i = 0;
		for (String s:un) {
			st[i++] = s;
		}
		System.out.println(Arrays.toString(st));
		return st;
  }
} 
